package com.gitee.ice1938.module.admin.framwork;

import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.web.ResourceProperties;
import org.springframework.boot.autoconfigure.web.servlet.error.DefaultErrorViewResolver;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自定义ErrorViewResolver
 * 
 * @author ice1938@qq.com
 *
 */
@Configuration
@AutoConfigureBefore(ErrorMvcAutoConfiguration.class)
public class AdminErrorViewResolverConfiguration {
	private final ApplicationContext applicationContext;

	private final ResourceProperties resourceProperties;

	public AdminErrorViewResolverConfiguration(ApplicationContext applicationContext,
	        ResourceProperties resourceProperties) {
		this.applicationContext = applicationContext;
		this.resourceProperties = resourceProperties;
	}

	/**
	 * 由于ErrorMvcAutoConfiguration 中使用DefaultErrorViewResolver 类型进行识别，所有必须返回类型为
	 * DefaultErrorViewResolver
	 * 
	 * @return
	 */
	@Bean
	@ConditionalOnMissingBean
	public DefaultErrorViewResolver conventionErrorViewResolver() {
		return new AdminErrorViewResolver(this.applicationContext, this.resourceProperties);
	}
}
